import { strict as assert } from 'node:assert';
import path from 'node:path';

import { readJSONSync } from 'utility';

import mm, { mock, type MockApplication } from './index.ts';
import { getBootstrapApp, setupApp } from './lib/app_handler.ts';
import { getEggOptions } from './lib/utils.ts';

const options = getEggOptions();

// throw error when an egg plugin test is using bootstrap
const pkgInfo = readJSONSync(path.join(options.baseDir || process.cwd(), 'package.json'));
if (pkgInfo.eggPlugin) {
  throw new Error('DO NOT USE bootstrap to test plugin');
}

const app: MockApplication = setupApp();

export { assert, getBootstrapApp, app, mm, mock, type MockApplication };
